package com.spdd.mt.app.api;

import com.spdd.mt.app.aop.sign.ValidateSign;
import com.spdd.mt.biz.manager.model.request.OrderMakeRequest;
import com.spdd.mt.biz.manager.model.request.OrderPreMakeRequest;
import com.spdd.mt.biz.manager.model.request.OrderQueryRequest;
import com.spdd.mt.biz.manager.model.response.OrderMakeResponse;
import com.spdd.mt.biz.manager.model.response.OrderPreMakeResponse;
import com.spdd.mt.biz.manager.model.response.OrderQueryResponse;
import com.spdd.mt.biz.manager.service.OrderService;
import com.spdd.mt.common.util.JacksonUtils;
import com.yomahub.tlog.core.annotation.TLogAspect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 话费充值接口
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class MobileController {

    @Autowired
    private OrderService orderService;

    // @PostMapping(value = "/test")
    // public WebResponse test(@RequestParam(value = "id") String id) {
    //     log.info("id = {}", id);
    //
    //     OrderMakeResponse response = new OrderMakeResponse(WebResponse.success(MtResponseStatus.MAKE_ORDER_SUCCESS));
    //     response.setPartnerOrderNo("partnerOrderNo");
    //
    //     return response;
    // }

    /**
     * 话费订单预下单充值接口
     *
     * @param preMakeRequest 充值请求参数
     */
    @ValidateSign
    @PostMapping(value = "/pre-make")
    public OrderPreMakeResponse orderPreMake(@RequestBody @Validated OrderPreMakeRequest preMakeRequest) {
        log.info("话费订单预下单充值接口，请求参数:{}", JacksonUtils.toJson(preMakeRequest));

        return orderService.orderPreMake(preMakeRequest);
    }

    /**
     * 话费订单充值接口
     *
     * @param makeRequest 充值请求参数
     */
    @ValidateSign
    @TLogAspect({"makeRequest.mtOrderNo"})
    @PostMapping(value = "/make")
    public OrderMakeResponse orderMake(@RequestBody @Validated OrderMakeRequest makeRequest) {
        log.info("话费订单充值接口，请求参数:{}", JacksonUtils.toJson(makeRequest));

        OrderMakeResponse response = orderService.recharge(makeRequest);
        log.info("充值接口响应为:{}", JacksonUtils.toJson(response));

        return response;
    }

    /**
     * 话费订单查询接口
     *
     * @param queryRequest 查询请求参数
     */
    @ValidateSign
    @TLogAspect({"queryRequest.mtOrderNo"})
    @PostMapping(value = "/query")
    public OrderQueryResponse orderQuery(@RequestBody @Validated OrderQueryRequest queryRequest) {
        log.info("话费订单查询接口，请求参数:{}", JacksonUtils.toJson(queryRequest));

        OrderQueryResponse response = orderService.query(queryRequest);
        log.info("查询接口响应为:{}", JacksonUtils.toJson(response));

        return response;
    }
}
